// 继承的应用

export  class Vechile {
  /** 品牌 */
  public brand: string;

  /** 车牌号 */
  public vechileNo: string;

  /** 租赁天数 */
  public days: number;

  /** 支付租赁的总费用 */
  public total!: number;

  /** 押金 */
  public deposit: number;

  constructor(
    _brand: string,
    _vechileNo: string,
    _days: number,
    _deposit: number
  ) {
    this.brand = _brand;
    this.vechileNo = _vechileNo;
    this.days = _days;
    this.deposit = _deposit;
  }

  // 计算租赁价格
  public calculateRent() {
    console.log(this.brand + " " + "车牌号为:" + this.vechileNo + "开始被租");
    return 0;
  }

  // 支付押金的方法
  public payDesposit() {
    console.log(
      this.brand + " " + "车牌号为:" + this.vechileNo + " 支付了" + this.total
    );
  }

  // 安全规则方法
  public safeShow() {
    console.log(this.brand + " " + "车牌号为:" + this.vechileNo + " 违规了");
  }
}

/**
 * 小轿车:
 *  型号[type]
 * calculateRent 计算租赁方法要重写
 */
 export class Car extends Vechile {
  public type: string;

  constructor(
    _brand: string,
    _vechileNo: string,
    _days: number,
    _deposit: number,
    _type: string
  ) {
    // 继承父类的构造函数
    super(_brand, _vechileNo, _days, _deposit);
    this.type = _type;
  }

  // 根据车的型号来获取租用一天该型号车的租金
  public getPriceByType() {
    let rentMoneyByDay: number = 0; //每天的租金
    if (this.type === "普拉多巡洋舰") {
      rentMoneyByDay = 800;
    } else if (this.type === "凯美瑞旗舰版") {
      rentMoneyByDay = 400;
    } else if (this.type === "威驰智行版") {
      rentMoneyByDay = 200;
    }
    return rentMoneyByDay;
  }

  public calculateRent(): number {
    // 天数 * 价格
    return this.days * this.getPriceByType();
  }
}

let car = new Car("普拉多", "京3A556", 3, 100000, "普拉多巡洋舰");
console.log("价格", car.calculateRent());

/**
 * 班车
 *
 */
 export class Bus extends Vechile {
  public type!: string;
  public seatNum: number; // 座位数

  constructor(
    _brand: string,
    _vechileNo: string,
    _days: number,
    _deposit: number,
    _seatNum: number
  ) {
    // 继承父类的构造函数
    super(_brand, _vechileNo, _days, _deposit);
    this.seatNum = _seatNum;
    if (this.seatNum > 200) {
      throw new Error("座位数不能超过200");
    }
  }

  public getPriceBySeatNum() {
    //计算租赁价格
    let rentMoneyByDay: number = 0; //每天的租金
    if (this.seatNum <= 16) {
      rentMoneyByDay = 800;
    } else if (this.seatNum > 16) {
      rentMoneyByDay = 1600;
    }
    return rentMoneyByDay;
  }

  // 根据座位数去计算价格
  public calculateRent() {
    // super调用父类函数
    super.calculateRent();
    return this.days * this.getPriceBySeatNum();
  }
}